package com.dq.eduservice.controller;

import com.dq.commonutils.dto.OrderCourseVo;
import com.dq.commonutils.vo.Result;
import com.dq.eduservice.entity.EduCourse;
import com.dq.eduservice.service.EduCourseService;
import com.dq.eduservice.vo.BasicCourseInfoVo;
import com.dq.eduservice.vo.CoursePubulishVo;
import com.dq.eduservice.vo.param.CourseParam;
import com.dq.eduservice.vo.param.PageParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * $tableInfo.name-API
 * @author Dq
 * @since 2022-07-22 19:48:50
 */
@RestController
@RequestMapping("eduservice/course")
public class EduCourseController {

    @Autowired
    private EduCourseService courseService;


    //课程列表功能 TODO

    /**
     * 获取课程基本信息列表
     * @param pageParam
     * @return
     */
    @PostMapping("getBasiceCourseBasicInfoList")
    public Result getCourseBasicInfo(@RequestBody PageParam pageParam){
        Map<String,Object> resultMap=courseService.getCourseBasicInfoByPageCondition(pageParam);
        return Result.success(resultMap);
    }

    /**
     * 添加课程信息
     * @param courseParam
     * @return
     */
    @PostMapping("addCourse")
    public Result addCourse (@RequestBody CourseParam courseParam){
        String courseId = courseService.addCourse(courseParam);
        HashMap<String, String> map = new HashMap<>();
        map.put("courseId",courseId);
        return Result.success(map);
    }

    /**
     * 查询Course基本信息
     * @param courseId
     * @return
     */
    @GetMapping("getCourseInfo/{courseId}")
    public Result getCourseInfo(@PathVariable String courseId){
        CourseParam courseParam  = courseService.getCourseInfo(courseId);
        return  Result.success(courseParam);
    }

    /**
     * 修改课程
     * @param courseParam
     * @return
     */
    @PostMapping("updateCourseInfo")
    public Result updateCourseInfo(@RequestBody CourseParam courseParam){
        courseService.updateCourseInfo(courseParam);
        return Result.success(null);
    }

    /**
     * 获取最终确认信息
     * @param courseId
     * @return
     */
    @GetMapping("getPublishCourseInfo/{courseId}")
    public Result getPublishCourseInfo(@PathVariable String courseId){
        CoursePubulishVo coursePubulishVo =courseService.getPublishCourseInfo(courseId);
        return Result.success(coursePubulishVo);
    }

    /**
     * 发布课程
     * @param courseId
     * @return
     */
    @PostMapping("publishCourse/{courseId}")
    public Result publishCourse(@PathVariable String courseId){
        EduCourse eduCourse = new EduCourse();
        eduCourse.setId(courseId);
        eduCourse.setStatus("Normal");
        courseService.updateById(eduCourse);
        return Result.success(null);
    }

    /**
     * 删除当前课程所有信息
     * @param courseId
     * @return
     */
    @PostMapping("deleteCourse/{courseId}")
    public Result deleteCourseAllInfo(@PathVariable String courseId){
        courseService.deleteCourseAllInfo(courseId);
        return Result.success(null);
    }


    // 远程调用
    /*
     @from service-order
    */

    /**
     * 查询Course基本信息
     * @param courseId
     * @return
     */
    @GetMapping("getOrderCourseInfo/{courseId}")
    public OrderCourseVo getOrderCourseInfo(@PathVariable("courseId") String courseId){
        OrderCourseVo orderCourseInfo  = courseService.getOrderCourseInfo(courseId);
        return  orderCourseInfo;
    }
}